/**
 * 
 */
package org.shark.jdbcTemplateTool.model;

import java.io.Serializable;
import java.util.List;

/**
 * @author lenovo
 * @description
 * @date 2016年8月16日
 */
@SuppressWarnings("serial")
public class Page<T> implements Serializable {

	// 一页显示的记录数
	private int pageSize;
	// 记录总数
	private int totalRows;
	// 总页数
	private int totalPages;
	// 当前页码
	private int currentPage;
	// 起始行数
	private int startIndex;
	// 结束行数
	private int lastIndex;
	// 结果集存放List
	private List<T> resultList;

	public int getCurrentPage() {
		return currentPage;
	}

	public void setCurrentPage(int currentPage) {
		this.currentPage = currentPage;
	}

	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int numPerPage) {
		this.pageSize = numPerPage;
	}

	public List<T> getResultList() {
		return resultList;
	}

	public void setResultList(List<T> resultList) {
		this.resultList = resultList;
	}

	public int getTotalPages() {
		return totalPages;
	}

	// 计算总页数
	public void setTotalPages() {
		if (totalRows % pageSize == 0) {
			this.totalPages = totalRows / pageSize;
		} else {
			this.totalPages = (totalRows / pageSize) + 1;
		}
	}

	public int getTotalRows() {
		return totalRows;
	}

	public void setTotalRows(int totalRows) {
		this.totalRows = totalRows;
	}

	public int getStartIndex() {
		return startIndex;
	}

	public void setStartIndex() {
		this.startIndex = (currentPage - 1) * pageSize;
	}

	public int getLastIndex() {
		return lastIndex;
	}

	// 计算结束时候的索引
	public void setLastIndex() {
		System.out.println("totalRows=" + totalRows);///////////
		System.out.println("numPerPage=" + pageSize);///////////
		if (totalRows < pageSize) {
			this.lastIndex = totalRows;
		} else if ((totalRows % pageSize == 0) || (totalRows % pageSize != 0 && currentPage < totalPages)) {
			this.lastIndex = currentPage * pageSize;
		} else if (totalRows % pageSize != 0 && currentPage == totalPages) {// 最后一页
			this.lastIndex = totalRows;
		}
	}

}
